//
//  ERToolsMainViewController.m
//  ExchangeRate
//
//  Created by lanou on 15/11/14.
//  Copyright © 2015年 方义强. All rights reserved.
//

#import "ERToolsMainViewController.h"
#import "ERSettingMainViewController.h"
#import "ERMapViewController.h"
#import "ERLangureChoiceViewController.h"
@interface ERToolsMainViewController ()

@end

@implementation ERToolsMainViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self rewriteTopView];
    [self createButton];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark 重写topView
- (void) rewriteTopView
{
    _leftButton.imageEdgeInsets = UIEdgeInsetsMake(10, 0, 10, 30);
    [_leftButton setImage:[UIImage imageNamed:@"iconfont-fanhui"] forState:(UIControlStateNormal)];
    [self.leftButton addTarget:self action:@selector(clickBackButton:) forControlEvents:(UIControlEventTouchUpInside)];
    
    self.titleLabel.text = NSLocalizedString(@"小工具", nil);
}

#pragma mark 点击返回按钮实现事件
- (void) clickBackButton:(UIButton *)btn
{
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark 创建button
- (void) createButton
{
    NSArray *titleArr = @[ NSLocalizedString(@"周边银行", nil), NSLocalizedString(@"语言切换", nil), NSLocalizedString(@"设置", nil), NSLocalizedString(@"期待更多", nil)];
    int i = 0;
    int j = 0;
    CGFloat btnW = (kSCREENWIDTH - 40) / 2;
    for (NSString *title in titleArr) {
        if (i > 1) {
            j = 1;
        }
        UIButton *button = [UIButton buttonWithType:(UIButtonTypeCustom)];
        button.frame = CGRectMake(20 + i % 2 * btnW , (kSCREENHEIGHT - 60 - btnW * 2) / 2 + j * btnW, btnW, btnW);
        [button setTitle:title forState:(UIControlStateNormal)];
        button.tag = kToolsButtonTag + i;
        [button setBackgroundColor:[UIColor colorWithRed:arc4random() % 256 / 255.0 green:arc4random() % 256 / 255.0 blue:arc4random() % 256 / 255.0 alpha:1.0]];
        [button addTarget:self action:@selector(clickToolsBtn:) forControlEvents:(UIControlEventTouchUpInside)];
        [self.view addSubview:button];
        i ++;
    }
}

#pragma mark 点击button 实现点击事件
- (void) clickToolsBtn:(UIButton *)btn
{
    switch (btn.tag - kToolsButtonTag) {
        case 0:
        {
            // 地图
            ERMapViewController *mapVC = [[ERMapViewController alloc] init];
            [self.navigationController pushViewController:mapVC animated:YES];
            break;
        }
           
        case 1:
        {
            // 更改语言
            ERLangureChoiceViewController *langureVC = [[ERLangureChoiceViewController alloc] init];
            [self.navigationController pushViewController:langureVC animated:YES];
            break;
        }
            
        case 2:
        {
            // 设置
            ERSettingMainViewController *settingVC = [[ERSettingMainViewController alloc] init];
            [self.navigationController pushViewController:settingVC animated:YES];
            break;
        }
            
        case 3:
        {
            // 暂定
            break;
        }
    }
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
